﻿import QtQuick 2.7
import QtQuick.Controls 1.5
import QtGraphicalEffects 1.0


import com.leamus.gamedata 1.0
//import "Temp.js" as PokeClass

Item {
    //property int type   //
    property int flags  //
    property bool bRectangularGlow: false
    property var userData

    property string pokeSource
    property string pokeBackSource


    property bool bEnable: (flags & PokeClass.Flag_Enable)           //是否可点
    property bool bClicked: (flags & PokeClass.Flag_Clicked)          //点击状态
    property bool bZhengMian : true//: (flags & PokeClass.flag_ZhengMian)
    property int iZBackup


    signal clicked(bool bClicked,var userData);            //点击发送信号,参数为状态
    signal debugMessage(string str)

    id: poke
    //enabled: false
    //visible: flags & PokeClass.flag_Show
    objectName: "pokeObject"
    transformOrigin: Item.Center



//这里是边框效果
    RectangularGlow {
        id: rectGlow
        visible: bRectangularGlow & poke.bEnable && (poke.bClicked)// || mouseArea.containsMouse)
        anchors.fill: rect;
        glowRadius: 7  //边框宽度
        spread: 0.4;    //虚化程度(0~1)
        color: poke.bClicked ? "lightgreen" : "blue"  //颜色
        //cornerRadius: rect.radius + glowRadius
    }

//牌的矩形
    Rectangle {
        id: rect
        width: poke.width
        height: poke.height
        //color: "red"

        //property alias buttonText: textItem.text	//


        //图片
        Image {
            id: image
            width: parent.width
            height: parent.height
            //source: "Pai101.jpg"
            //anchors.fill: parent

        }

        //阴影
        DropShadow {
            anchors.fill: image; source: image
            horizontalOffset: 4; verticalOffset: 4
            radius: 12.0; samples: 16; color: "#80000000";
        }

        //颜色遮罩(不可用时黑色,source必须和本对象同一层次!!!)
        ColorOverlay {
            id: colorOverlay
            visible: !poke.bEnable
            anchors.fill: image;
            source: image;
            color: "#80000000"
        }

        //鼠标事件
        MouseArea {
            id: mouseArea
            enabled: poke.bEnable
            hoverEnabled: true
            anchors.fill: image
            onClicked: {
                //console.log(mouse.x);
                //console.log(width);
                if(bEnable)
                {
                    //bClicked = !bClicked
                    //flags ^= PokeClass.flag_Clicked
                    poke.clicked(bClicked,userData);
                    //poke.scale = 1;
                    //console.debug("qml中点击是:",userData)
                }
                //console.debug("onClicked")
            }
            onEntered: if(bEnable){poke.scale = 1.03; iZBackup = poke.z; poke.z *= 2;}
            onExited: {poke.scale = 1; poke.z /= 2;}
            onDoubleClicked: {
                console.debug("userData:",userData,pokeSource,poke.z)
                debugMessage("poke data:" + userData + pokeSource + poke.z)
            }
            //onPressAndHold: console.debug("onPressAndHold")
            //onPressed: console.debug("onPressed")
            //onReleased: console.debug("onReleased")
        }


/*
        Glow {
            anchors.fill: image; source: image
            radius: 16; samples: 24
            color: "red"; spread: 0.01
            fast: true;
        }
        */


    }

    //特效
    Behavior on x {
        NumberAnimation {
            duration: 1000
            easing.type: Easing.OutQuint
        }
    }
    Behavior on y {
        NumberAnimation {
            duration: 1000
            easing.type: Easing.OutQuint
        }
    }
    Behavior on scale {
        NumberAnimation {
            duration: 200
            //easing.type: Easing.OutQuint
        }
    }

    //点击
    /*
    onClick: {
        console.log(bClicked);
        x = x+100;
        y = y+200;
        if(x >= 500)x=0;
        if(y >= 500)y=0;

        //image.source = "1.jpg"
    }
    */

    Component.onCompleted: {
    }

    onEnabledChanged: {

    }

    function changeSource() {
        if(bZhengMian)
            image.source = pokeSource;
        else
            image.source = pokeBackSource;

    }

    onBZhengMianChanged: {
        changeSource();
    }
    onPokeSourceChanged: changeSource()
    onPokeBackSourceChanged: changeSource()
}

